package edu.ccut.saturn.component.impl.directory;

import java.util.Enumeration;

import org.osgi.framework.Bundle;

import edu.ccut.saturn.component.IBundleInfo;
import edu.ccut.saturn.component.SaturnComponentException;

public class SaturnSCADirectoryInfo extends AbstractDirectoryInfo {

	private static final String SATURN_SCA_FILE_POSTFIX = ".composite";

	public SaturnSCADirectoryInfo() {
		super(SATURN_DIRECTORY_TYPE_SCA);
	}

	@SuppressWarnings("unchecked")
	public void load(Bundle bundle, IBundleInfo bundleInfo) {
		Enumeration<String> dataFiles = bundle.getEntryPaths(super
				.getDirectoryPath());

		while (dataFiles.hasMoreElements()) {
			String dataFile = dataFiles.nextElement();

			try {

				if (dataFile != null
						&& dataFile.endsWith(SATURN_SCA_FILE_POSTFIX)) {

					bundleInfo.getBundleSCAInfo().addSCACompositeFilePath(
							bundle.getEntry(dataFile));
				}

			} catch (SaturnComponentException e) {
				logger.error("load SCA failed! the file name is \"" + dataFile
						+ "\" in bundle [" + bundle.getSymbolicName() + "]");
			}
		}
	}
}